<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('单据提交列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>标题：</label>
                            <input type="text" name="msg"/>
                        </li>
                        <li>
                            <label>状态：</label>
                            <select name="statusCode">
                                <option value=2 selected>已审核</option>
                                <option value=4 >开发中</option>
                                <option value=5 >已完成</option>
                            </select>
                        </li>
                        <li>
                            <label>科室：</label>
                            <select name="deptId">
                                <option th:each="dept:${depts}" th:value="${dept.deptId}" th:text="${dept.deptName}" ></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
    <div class="modal inmodal fade" id="myModal6" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                    </button>
                    <h4 class="modal-title">分配开发人员</h4>
                </div>
                <div class="modal-body">
                    <input type="hidden" id="workId"/>
                    <select id="naEmp" class="form-control m-b" th:with="type=${@sysUserService.selectUserByIdDept(103)}">
                        <option th:each="item : ${type}" th:text="${item.userName}" th:value="${item.userName}"></option>
                    </select>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="agree()">确定</button>
                </div>
            </div>
        </div>
    </div>
    <div class="modal inmodal fade" id="myModal7" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                    </button>
                    <h4 class="modal-title">实际工作量(人天，可精确到1位小数)</h4>
                </div>
                <div class="modal-body">
                    <input type="hidden" id="workId2"/>
                    <input type="text" id="days" class="form-control m-b" />
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="end()">确定</button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal inmodal fade" id="myModal8" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                    </button>
                    <h4 class="modal-title">驳回原因</h4>
                </div>
                <div class="modal-body">
                    <input type="hidden" id="workId3"/>
                    <textarea id="note" class="form-control m-b" ></textarea>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="reback()">确定</button>
                </div>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:flow:edit')}]];
    var editNoteFlag = [[${@permission.hasPermi('system:flow:editNote:view')}]];
    var removeFlag = [[${@permission.hasPermi('system:flow:remove')}]];
    var prefix = ctx + "system/flow";
    function updateStutusById(ids,status) {
        $.ajax({
            url: prefix+"/edit?ids="+ids+"&status="+status,
            cache: false,
            contentType: false,
            processData: false,
            type: 'Po',
            success: function (result) {
                $("#bootstrap-table").bootstrapTable('refresh');
                layer.alert(result);
            }
        });
    }
    
    function openModel(workId) {
        $("#workId").val(workId);
        $("#myModal6").modal("show");
    }

    function agree() {
        $("#myModal6").modal("hide");
        $.ajax({
            url: prefix+"/updateStatus?ids="+$("#workId").val()+"&status=4"+status+"&naEmp="+$("#naEmp").val(),
            cache: false,
            contentType: false,
            processData: false,
            type: 'GET',
            success: function (result) {
                $("#bootstrap-table").bootstrapTable('refresh');
                $.modal.alertSuccess(result);
            }
        });
    }
    function openEndModel(workId) {
        $("#workId2").val(workId);
        $("#myModal7").modal("show");
    }

    function reback() {
        var workId = $("#workId3").val();
        var note = $("#note").val();
        debugger;
        $.ajax({
            url: prefix+"/addNote?note="+note+"&workId="+workId,
            cache: false,
            contentType: false,
            processData: false,
            type: 'post',
            success: function (result) {
                $("#note").val("");
                $("#myModal8").modal("hide");
                updateStatusExec(workId,3);
            }
        });
    }

    function end() {
        var days = $("#days").val();
        if(days<=0) {
            $.modal.alertError("工作量需为大于0的正整数");
            return;
        }
        $("#myModal7").modal("hide");
        $.ajax({
            url: prefix+"/updateStatus?ids="+$("#workId2").val()+"&status=5&days="+days,
            cache: false,
            contentType: false,
            processData: false,
            type: 'GET',
            success: function (result) {
                $("#bootstrap-table").bootstrapTable('refresh');
                $.modal.alertSuccess(result);
            }
        });
    }

    var updateStatusExec = function(id,status) {
        if(naEmp==undefined) {
            naEmp=="";
        }
        $.ajax({
            url: prefix+"/updateStatus?ids="+id+"&status="+status,
            cache: false,
            contentType: false,
            processData: false,
            type: 'GET',
            success: function (result) {
                $("#bootstrap-table").bootstrapTable('refresh');
                $.modal.alertSuccess(result);
            }
        });
    }

    function updateStutus(id,status,name,naEmp) {
        var title;
        if(status==2) {
            title = "确定要审核"+name+"提交的需求吗？";
        } else if(status==3) {
            $("#workId3").val(id);
            $("#myModal8").modal("show");
            return;
        } else if(status==4) {
            title = "确定同意开发"+name+"提交的需求吗？";
        } else if(status==5) {
            title = "确定要完结"+name+"提交的需求吗？";
        }
        $.modal.confirm(title, function() {
            updateStatusExec(id,status);
        });
    }

    function editNoteOpen(workId){
        var url= prefix+"/editNote?workId="+workId;
        $.modal.openTab("查看", url);

    }

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "单据提交",
            columns: [{
                checkbox: true
            },
                {
                    field: 'workId',
                    title: '',
                    visible: false
                },
                {
                    field: 'deptName',
                    title: '科室名称'
                },
                {
                    field: 'title',
                    title: '标题'
                },
                {
                    field: 'statusCode',
                    title: '状态',
                    formatter: function (value, item, index) {
                        if (item.statusCode == 0) {
                            return "新建";
                        } else if (item.statusCode == 1) {
                            return "<span style='color:red'>提交</span>";
                        } else if (item.statusCode == 2) {
                            return "<span style='color:red'>已审核</span>";
                        } else if (item.statusCode == 3) {
                            return "<span style='color:red'>驳回</span>";
                        } else if (item.statusCode == 4) {
                            return "<span style='color:red'>开发中</span>";
                        } else if (item.statusCode == 5) {
                            return "<span style='color:red'>已完成</span>";
                        }
                    }
                },
                {
                    field: 'euFreq',
                    title: '频次',
                    formatter: function (value, item, index) {
                        if (item.euFreq == 1) {
                            return "小于一月";
                        } else if (item.euFreq == 2) {
                            return "小于一季";
                        } else if (item.euFreq == 3) {
                            return "小于一年";
                        } else if (item.euFreq == 4) {
                            return "仅此一次";
                        }
                    }
                },
                {
                    field: 'fgUrgent',
                    title: '加急标志',
                    formatter: function (value, item, index) {
                        if (item.fgUrgent == 0) {
                            return "正常";
                        } else if (item.fgUrgent == 1) {
                            return "<span style='color:red'>加急</span>";
                        }
                    }
                },
                {
                    field: 'naEmp',
                    title: '执行人'
                },
                {
                    field: 'lastDate',
                    title: '最后日期'
                },
                {
                    field: 'naEmpCre',
                    title: '创建人'
                },
                {
                    field: 'dtSysCre',
                    title: '创建日期'
                },
                {
                    field: 'days',
                    title: '工作量（人天）'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="editNoteOpen(\'' + row.workId + '\')"><i class="fa fa-eye"></i>查看</a> ');
                        if(row.statusCode == 2) { //已审核
                            actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="openModel(\''+row.workId+'\')"><i class="fa fa-check"></i>同意</a> ');
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="updateStutus(\'' + row.workId + '\',3,\''+row.naEmpCre+'\',\'\')"><i class="fa fa-remove"></i>驳回</a> ');
                        } else if(row.statusCode == 4) { //开发中
                            actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="openModel(\''+row.workId+'\')"><i class="fa fa-check"></i>指派</a> ');
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="openEndModel(\'' + row.workId + '\')"><i class="fa fa-check"></i>完成</a> ');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });
</script>
</body>
</html>